from __future__ import absolute_import, print_function, division

import os
import time
from multiprocessing import Process, current_process


def daemon():
    pinfo = current_process()
    print('Starting:', pinfo.name)
    with open("d1.pid", "w") as f:
        f.write(str(pinfo.pid))
    print("Pid:", pinfo.pid)
    while 1:
        time.sleep(2)
        print("running...")
    print('Exiting :', pinfo.name)

if __name__ == "__main__":
    p = Process(name="Daemon", target=daemon)
    p.daemon = True
    p.start()
    #p.join()
